#!/bin/sh

echo =================================
echo  $(date "+%Y-%m-%d %H:%M:%S") 自动化部署脚本启动
echo =================================

echo $(date "+%Y-%m-%d %H:%M:%S") 停止原来运行中的工程
APP_NAME=reggie

tpid=`ps -ef|grep ${APP_NAME}|grep -v grep|grep -v $$|awk '{print $2}'`
if [[ ${tpid} != "" ]]; then
    echo '当前进程号:' $tpid
    echo 'Stop Process...'
    kill -15 $tpid
fi
sleep 3

tpid=`ps -ef|grep ${APP_NAME}|grep -v grep|grep -v $$|awk '{print $2}'`

if [[ ${tpid} != "" ]]; then
    echo '当前进程号:' $tpid '任然存在'
    echo 'Kill Process!'
    kill -9 $tpid
else
    echo 'Stop Success!'
fi



echo $(date "+%Y-%m-%d %H:%M:%S") 准备从Git仓库拉取最新代码
cd /opt/local/reggie

echo $(date "+%Y-%m-%d %H:%M:%S") 开始从Git仓库拉取最新代码
git pull
echo currTime 代码拉取完成

echo $(date "+%Y-%m-%d %H:%M:%S") 开始打包
output=`mvn clean package -Dmaven.test.skip=true`

cd target

echo $(date "+%Y-%m-%d %H:%M:%S") 启动项目
nohup java -jar reggie-1.0-SNAPSHOT.jar &> reggie.log &
echo $(date "+%Y-%m-%d %H:%M:%S") 项目启动完成

